/*
*A 0 0 0 (0,0)
 9 6 0 0 (1,0) (1,1)
 4 8 0 0
 3 7 5 2
* */

public class 第二题 {
    public static int count = 0;

    public static void main(String[] args) {
        getPermutation("123456789");
        System.out.println(count+" "+count/6);
    }

    private static void getPermutation(String s) {
        char[] array = s.toCharArray();
        getPermutationCore(array, 0);
    }

    private static void getPermutationCore(char[] array, int k) {
        if (array.length == k) {
            int[][] arr = new int[4][4];
            int a1 = 0;
            int a2 = 0;
            arr[0][0] = Integer.parseInt(array[0] + "");
            arr[1][0] = Integer.parseInt(array[1] + "");
            arr[1][1] = Integer.parseInt(array[2] + "");
            arr[2][0] = Integer.parseInt(array[3] + "");
            arr[2][1] = Integer.parseInt(array[4] + "");
            arr[3][0] = Integer.parseInt(array[5] + "");
            arr[3][1] = Integer.parseInt(array[6] + "");
            arr[3][2] = Integer.parseInt(array[7] + "");
            arr[3][3] = Integer.parseInt(array[8] + "");
            for (int i = 0; i < 4; i++) {
                a1 += arr[i][0];
                a2 += arr[3][i];
            }

            int a3 = arr[0][0] + arr[1][1] + arr[2][1] + arr[3][3];
            if (a1==a2&&a2==a3){
                count++;
            }
            //System.out.println(new String(array));
        }

        for (int i = k; i < array.length; i++) {
            swap(array, i, k);
            getPermutationCore(array, k + 1);
            swap(array, i, k);
        }
    }

    private static void swap(char[] array, int i, int k) {
        char temp = array[i];
        array[i] = array[k];
        array[k] = temp;

    }
}
